package com.wutong.engine.entity;

import com.almasb.fxgl.dsl.FXGL;
import com.wutong.engine.anything.Anything;
import com.wutong.engine.anything.GameLogger;
import com.wutong.engine.entity.interfaces.EffectFunction;
import javafx.util.Duration;
import org.slf4j.Logger;

import java.util.ArrayList;

/**
 * 生物状态类，可以被继承和覆写
 *
 * @author 王益凡
 */

abstract public class BiologicalState {
    private static final Logger log = GameLogger.getLogger(BiologicalState.class);

    private static int stateId = 1000;
    private final int id;

    private String stateName;
    private String stateDisc;

    private Duration duration;

    // 效果执行接口
    private final ArrayList<EffectFunction> effectFunctions = new ArrayList<>();

    protected BiologicalState(String stateName, String stateDisc) {
        this.stateName = stateName;
        this.stateDisc = stateDisc;
        this.id = stateId++;
        log.debug("成功创建效果 {} -> {}", stateName, stateDisc);
    }

    public void effective(GameEntity gameEntity, Duration duration) {
        for (EffectFunction function : effectFunctions) {
            Anything.run("Effective", () -> function.run(gameEntity), duration);
        }
    }

    protected void addEffect(EffectFunction function) {
        effectFunctions.add(function);
    }

    public String getStateName() {
        return stateName;
    }

    public void setStateName(String stateName) {
        this.stateName = stateName;
    }

    public String getStateDisc() {
        return stateDisc;
    }

    public void setStateDisc(String stateDisc) {
        this.stateDisc = stateDisc;
    }

    public int getId() {
        return id;
    }


    @Override
    public String toString() {
        return "BiologicalState {stateName = %s, stateDisc = %s} By Id = %d".formatted(stateName, stateDisc, id);
    }
}
